from flask import render_template, request, jsonify, current_app
from . import keypoints_bp
import os
from werkzeug.utils import secure_filename

@keypoints_bp.route('/')
def index():
    return render_template('modules/keypoint_detection.html')

@keypoints_bp.route('/process', methods=['POST'])
def process():
    if 'image' not in request.files:
        return jsonify({'success': False, 'message': '没有上传文件'})
    
    file = request.files['image']
    if file.filename == '':
        return jsonify({'success': False, 'message': '没有选择文件'})
    
    if file:
        filename = secure_filename(file.filename)
        file_path = os.path.join(current_app.config['UPLOAD_FOLDER'], filename)
        file.save(file_path)
        
        # 关键点检测逻辑
        result = {
            'keypoints': [
                {'name': '头部', 'position': [150, 50]},
                {'name': '左肩', 'position': [100, 100]},
                {'name': '右肩', 'position': [200, 100]}
            ]
        }
        
        return jsonify({
            'success': True,
            'result': result
        }) 